package com.bestv.search.spider.youku.sync;

import com.bestv.search.spider.model.VideoBaseInfo;
import com.bestv.search.spider.service.PersonManager;
import com.bestv.search.spider.service.VideoBaseInfoManager;
import com.bestv.search.spider.util.PropertyStrategyWrapper;
import com.bestv.search.spider.util.SpiderConst;
import com.bestv.search.spider.util.SpiderUtil;
import com.bestv.search.spider.util.StringUtil;
import com.bestv.search.spider.youku.model.YouKuGenre;
import com.bestv.search.spider.youku.model.YouKuVideoBaseInfoJSON;
import com.bestv.search.spider.youku.model.YouKuVideoDetailInfo;
import com.bestv.search.spider.youku.model.YouKuVideoDetailInfoJSON;
import com.bestv.search.spider.youku.model.attr.Person;
import com.bestv.search.spider.youku.model.attr.VideoAttr;
import com.bestv.search.spider.youku.service.YouKuVideoDetailInfoManager;
import com.bestv.search.spider.youku.util.YouKuAppKeyPool;
import com.bestv.search.spider.youku.util.YouKuUtil;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.util.PropertySetStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

public class YouKuVideoInfoSyncer extends QuartzJobBean {
    private static boolean isRunning = false;
    private final Log log = LogFactory.getLog(YouKuVideoInfoSyncer.class);
    private VideoBaseInfoManager infoManager;
    private YouKuVideoDetailInfoManager youKuVideoDetailInfoManager;
    private PersonManager personManager;
    private String isfullSync;
    private String infoFolder;

    private static String getAllVideosURLCacheFile() {
        String cacheFolder = YouKuVideoInfoSyncer.class.getClassLoader().getResource(File.separator).getPath()
                + SpiderConst.CACHE;
        File folder = new File(cacheFolder);
        if (!folder.exists()) {
            folder.mkdir();
        }

        return cacheFolder + File.separator + SpiderConst.YOUKU_ALL_VIDEOS_URL_FILE;
    }

    @Override
    protected void executeInternal(JobExecutionContext arg) throws JobExecutionException {
        if (!isRunning) {
            isRunning = true;
            List<String> leaveUrls = null;

            // Set running flag
            Calendar c = Calendar.getInstance();
            String fileFolderPath = getFileFolderByDateTime(c.getTime());

            // remove over 7 days' files.
            String parentFolder = fileFolderPath + File.separator + SpiderConst.POINT + SpiderConst.POINT
                    + File.separator;
            String[] overdueFolders = SpiderUtil.getOver7DaysFolders(parentFolder);
            if (overdueFolders != null) {
                for (String path : overdueFolders) {
                    SpiderUtil.deleteDirectory(parentFolder + path);
                }
            }

            String isRunningFile = fileFolderPath + File.separator + SpiderConst.ISRUNNING_FLAG_FILE;
            SpiderUtil.createFile(isRunningFile);

            boolean syncFinished = false;
            do {
                if (!YouKuAppKeyPool.isBusy) {
                    if (isfullSync != null && isfullSync.equalsIgnoreCase(SpiderConst.Y)) {
                        // start full sync
                        log.info("Start sync all videos's info from YouKu @" + new Date());
                        syncFinished = syncAllVideosInfoFromYKU();
                    } else {
                        log.info("Start increase sync videos info from youku ");

                        if (leaveUrls == null || leaveUrls.size() == 0) {
                            leaveUrls = getSyncNewVideosURLFromYKU();
                        }

                        // Sync new videos
                        leaveUrls = syncNewVideosInfoFromYKU(leaveUrls);

                        // Sync finished, end this loop.
                        if (leaveUrls == null || leaveUrls.size() == 0) {
                            syncFinished = true;
                        }
                    }
                } else {
                    try {
                        Thread.sleep(SpiderConst.THREAD_CHECK_INTERVAL_SECOND * 1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            } while (!syncFinished);

            // Writes videos info to file as JSON format
            String file = fileFolderPath + File.separator + SpiderConst.YOUKU_ALL_VIDEOS_FILE;
            List<YouKuVideoDetailInfo> list = youKuVideoDetailInfoManager.getAll();
            for (YouKuVideoDetailInfo info : list) {
                String json = convertToJson(info);
                SpiderUtil.addTextToFile(json, file);
            }
            SpiderUtil.deleteFile(isRunningFile);

            isRunning = false;
            log.info("Sync all videos's info from YouKu end @" + new Date());
        } else {
            log.info("Last video sync process is still running");
        }
    }

    /**
     * Sync all video from youku
     *
     * @return whether sync finished.
     */
    private boolean syncAllVideosInfoFromYKU() {
        List<String> leaveUrls = new ArrayList<String>();
        File cacheFile = getAllVideosURLByCategory();
        BufferedReader br = null;
        FileReader fr = null;
        try {
            fr = new FileReader(cacheFile);
            br = new BufferedReader(fr);
            String url = null;
            while ((url = br.readLine()) != null) {
                boolean isHandle = handleRequest(url);
                if (!isHandle) {
                    leaveUrls.add(url);
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e);
        } finally {

            try {
                if (fr != null) {
                    fr.close();
                }
                if (br != null) {
                    br.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
                log.error(e);
            }
        }
        if (leaveUrls != null && leaveUrls.size() != 0) {
            // Write leave url back to cache file
            FileWriter fw = null;
            BufferedWriter bw = null;
            try {
                fw = new FileWriter(cacheFile);
                bw = new BufferedWriter(fw);
                for (String line : leaveUrls) {
                    bw.write(line + SpiderConst.LINE_SEPARATOR);
                    bw.flush();
                }
            } catch (IOException e) {
                log.error(e);
                e.printStackTrace();
            } finally {
                try {
                    if (fw != null) {
                        fw.close();
                    }
                    if (bw != null) {
                        bw.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                    log.error(e);
                }
            }
        } else {
            cacheFile.delete();
            // sync finished
            return true;
        }
        // don't sync finished
        return false;
    }

    private List<String> syncNewVideosInfoFromYKU(List<String> urls) {
        List<String> leaveUrls = new ArrayList<String>();
        for (String url : urls) {

            String response = null;
            if (!YouKuAppKeyPool.isBusy) {
                do {
                    response = new YouKuUtil().sendRequestByAppKey(url);
                    if (YouKuAppKeyPool.isBusy) {
                        break;
                    }
                } while (response == null);

                // convert to object and save to DB
                if (response != null && !response.equalsIgnoreCase(SpiderConst.EMPTY)) {
                    JSONObject json = JSONObject.fromObject(StringUtil.ascii2Native(response));
                    JsonConfig cfg = new JsonConfig();
                    cfg.setPropertySetStrategy(new PropertyStrategyWrapper(PropertySetStrategy.DEFAULT));
                    cfg.setRootClass(YouKuVideoBaseInfoJSON.class);
                    YouKuVideoBaseInfoJSON infoArray = (YouKuVideoBaseInfoJSON) JSONObject.toBean(json, cfg);

                    if (infoArray.getShows().length > 0) {
                        // Sync details info
                        StringBuffer ids = new StringBuffer();
                        for (int i = 0; i < infoArray.getShows().length; i++) {
                            ids.append(infoArray.getShows()[i].getId());
                            if (i < infoArray.getShows().length - 1) {
                                ids.append(SpiderConst.COMMA);
                            }
                        }
                        String detailsURL = StringUtil.buildBuffer(
                                new String[]{SpiderConst.YOUKU_SHOWS_DETAIL_BATCH_URL, SpiderConst.SHOW_IDS,
                                        SpiderConst.EQUAL_FLAG, ids.toString()}).toString();

                        String detailsResponse = null;
                        if (!YouKuAppKeyPool.isBusy) {
                            do {
                                detailsResponse = new YouKuUtil().sendRequestByAppKey(detailsURL);
                                if (YouKuAppKeyPool.isBusy) {
                                    break;
                                }
                            } while (detailsResponse == null);

                            if (detailsResponse != null && !detailsResponse.equalsIgnoreCase(SpiderConst.EMPTY)) {
                                // convert details info to object
                                JSONObject jsonDetails = JSONObject
                                        .fromObject(StringUtil.ascii2Native(detailsResponse));
                                JsonConfig detailcfg = new JsonConfig();
                                detailcfg.setPropertySetStrategy(new PropertyStrategyWrapper(
                                        PropertySetStrategy.DEFAULT));
                                detailcfg.setRootClass(YouKuVideoDetailInfoJSON.class);
                                YouKuVideoDetailInfoJSON infoDetailsArray = (YouKuVideoDetailInfoJSON) JSONObject
                                        .toBean(jsonDetails, detailcfg);

                                // Saves to DB
                                infoManager.saveOrUpdate(convert(infoDetailsArray));

                                // Saves all persons to DB
                                List<com.bestv.search.spider.model.Person> list = getPersonList(infoDetailsArray);
                                personManager.saveList(list);
                            } else {
                                leaveUrls.add(url);
                            }
                        } else {
                            leaveUrls.add(url);
                        }
                    }
                } else {
                    leaveUrls.add(url);
                }
            } else {
                leaveUrls.add(url);
            }
        }

        return leaveUrls;
    }

    /**
     * Gets top 50 for each genre type as new video that is order by updated.
     *
     * @return urls that used to sync new videos.
     */
    private List<String> getSyncNewVideosURLFromYKU() {
        List<String> urls = new ArrayList<String>();

        Map<String, YouKuGenre[]> genres = YouKuUtil.getSyncGenreTypes();
        // Add type field, etc. 电影。电视剧
        for (String type : genres.keySet()) {
            StringBuffer typeField = StringUtil.buildBuffer(new String[]{SpiderConst.CATEGORY,
                    SpiderConst.EQUAL_FLAG, StringUtil.convertToURLEncoder(type, SpiderConst.UTF_8)});
            // Add genre field, etc. 喜剧，动作
            for (YouKuGenre genre : genres.get(type)) {
                StringBuffer genreField = StringUtil.buildBuffer(new String[]{SpiderConst.URL_SPLIT_FLAG,
                        SpiderConst.GENRE, SpiderConst.EQUAL_FLAG,
                        StringUtil.convertToURLEncoder(genre.getLabel(), SpiderConst.UTF_8)});

                String requestURL = StringUtil.buildBuffer(
                        new String[]{SpiderConst.YOUKU_SHOWS_BY_CATEGORY_URL, typeField.toString(),
                                genreField.toString(), SpiderConst.URL_SPLIT_FLAG, SpiderConst.PAGE,
                                SpiderConst.EQUAL_FLAG, String.valueOf(1), SpiderConst.URL_SPLIT_FLAG,
                                SpiderConst.COUNT, SpiderConst.EQUAL_FLAG, String.valueOf(50),
                                SpiderConst.URL_SPLIT_FLAG, SpiderConst.ORDERBY, SpiderConst.EQUAL_FLAG,
                                SpiderConst.UPDATED}).toString();

                urls.add(requestURL);
            }
        }

        return urls;
    }

    private File getAllVideosURLByCategory() {
        File cacheFile = null;
        FileOutputStream out = null;
        PrintWriter pw = null;
        try {
            cacheFile = new File(getAllVideosURLCacheFile());
            if (!cacheFile.exists()) {
                cacheFile.createNewFile();
                out = new FileOutputStream(cacheFile);
                pw = new PrintWriter(out, true);

                Map<String, YouKuGenre[]> genres = YouKuUtil.getSyncGenreTypes();
                // Add type field, etc. 电影。电视剧
                for (String type : genres.keySet()) {
                    StringBuffer typeField = StringUtil.buildBuffer(new String[]{SpiderConst.CATEGORY,
                            SpiderConst.EQUAL_FLAG, StringUtil.convertToURLEncoder(type, SpiderConst.UTF_8)});
                    // Add genre field, etc. 喜剧，动作
                    for (YouKuGenre genre : genres.get(type)) {
                        StringBuffer genreField = StringUtil.buildBuffer(new String[]{SpiderConst.URL_SPLIT_FLAG,
                                SpiderConst.GENRE, SpiderConst.EQUAL_FLAG,
                                StringUtil.convertToURLEncoder(genre.getLabel(), SpiderConst.UTF_8)});
                        // Add area field, etc. 大陆，香港
                        for (String area : YouKuUtil.getSyncAreas()) {
                            StringBuffer areaField = StringUtil.buildBuffer(new String[]{SpiderConst.URL_SPLIT_FLAG,
                                    SpiderConst.AREA, SpiderConst.EQUAL_FLAG,
                                    StringUtil.convertToURLEncoder(area, SpiderConst.UTF_8)});
                            // Add year field, etc. 2000, 2001
                            for (int year : YouKuUtil.getSyncYears()) {
                                StringBuffer yearField = StringUtil.buildBuffer(new String[]{
                                        SpiderConst.URL_SPLIT_FLAG, SpiderConst.RELEASE_YEAR, SpiderConst.EQUAL_FLAG,
                                        String.valueOf(year)});
                                // Video is charge or free, 0 is free, 1 is
                                // charge
                                for (int i = 0; i < 2; i++) {
                                    StringBuffer paidField = StringUtil.buildBuffer(new String[]{
                                            SpiderConst.URL_SPLIT_FLAG, SpiderConst.PAID, SpiderConst.EQUAL_FLAG,
                                            String.valueOf(i)});

                                    // Add order by field
                                    StringBuffer orderbyField = StringUtil.buildBuffer(new String[]{
                                            SpiderConst.URL_SPLIT_FLAG, SpiderConst.ORDERBY, SpiderConst.EQUAL_FLAG,
                                            SpiderConst.UPDATED});

                                    // Genre to URL.
                                    StringBuffer url = StringUtil.buildBuffer(new String[]{
                                            SpiderConst.YOUKU_SHOWS_BY_CATEGORY_URL, typeField.toString(),
                                            genreField.toString(), areaField.toString(), yearField.toString(),
                                            paidField.toString(), orderbyField.toString()});

                                    pw.write(url.toString() + SpiderConst.LINE_SEPARATOR);
                                    pw.flush();
                                }
                            }
                        }
                    }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            log.error(e);
        } finally {
            if (pw != null) {
                pw.close();
            }
            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return cacheFile;
    }

    private boolean handleRequest(String url) {
        if (url != null) {
            int pageIndex = 1;
            int pageSize = 0;
            do {
                String response = null;
                String requestURL = StringUtil.buildBuffer(
                        new String[]{url.toString(), SpiderConst.URL_SPLIT_FLAG, SpiderConst.PAGE,
                                SpiderConst.EQUAL_FLAG, String.valueOf(pageIndex), SpiderConst.URL_SPLIT_FLAG,
                                SpiderConst.COUNT, SpiderConst.EQUAL_FLAG,
                                String.valueOf(SpiderConst.YOUKU_DEFAULT_PAGE_COUNT)}).toString();
                if (!YouKuAppKeyPool.isBusy) {
                    do {
                        response = new YouKuUtil().sendRequestByAppKey(requestURL);
                        if (YouKuAppKeyPool.isBusy) {
                            break;
                        }
                    } while (response == null);

                    // convert to object and save to DB
                    if (response != null && !response.equalsIgnoreCase(SpiderConst.EMPTY)) {
                        JSONObject json = JSONObject.fromObject(StringUtil.ascii2Native(response));
                        JsonConfig cfg = new JsonConfig();
                        cfg.setPropertySetStrategy(new PropertyStrategyWrapper(PropertySetStrategy.DEFAULT));
                        cfg.setRootClass(YouKuVideoBaseInfoJSON.class);
                        YouKuVideoBaseInfoJSON infoArray = (YouKuVideoBaseInfoJSON) JSONObject.toBean(json, cfg);

                        if (Integer.valueOf(infoArray.getTotal()) > 0) {

                            // gets page size
                            pageSize = Integer.valueOf(infoArray.getTotal()) / SpiderConst.YOUKU_DEFAULT_PAGE_COUNT;
                            if (Integer.valueOf(infoArray.getTotal()) % SpiderConst.YOUKU_DEFAULT_PAGE_COUNT != 0) {
                                pageSize = pageSize + 1;
                            }

                            // YouKu limit, page*count must more smaller than
                            // 1000.
                            if (pageSize * SpiderConst.YOUKU_DEFAULT_PAGE_COUNT > 1000) {
                                pageSize = 1000 / SpiderConst.YOUKU_DEFAULT_PAGE_COUNT;
                            }

                            // Sync details info
                            StringBuffer ids = new StringBuffer();
                            for (int i = 0; i < infoArray.getShows().length; i++) {
                                ids.append(infoArray.getShows()[i].getId());
                                if (i < infoArray.getShows().length - 1) {
                                    ids.append(SpiderConst.COMMA);
                                }
                            }

                            String detailsURL = StringUtil.buildBuffer(
                                    new String[]{SpiderConst.YOUKU_SHOWS_DETAIL_BATCH_URL, SpiderConst.SHOW_IDS,
                                            SpiderConst.EQUAL_FLAG, ids.toString()}).toString();

                            String detailsResponse = null;
                            if (!YouKuAppKeyPool.isBusy) {
                                do {
                                    detailsResponse = new YouKuUtil().sendRequestByAppKey(detailsURL);
                                    if (YouKuAppKeyPool.isBusy) {
                                        break;
                                    }
                                } while (detailsResponse == null);
                                if (detailsResponse != null && !detailsResponse.equalsIgnoreCase(SpiderConst.EMPTY)) {
                                    // convert details info to object
                                    JSONObject jsonDetails = JSONObject.fromObject(StringUtil
                                            .ascii2Native(detailsResponse));
                                    JsonConfig detailsCfg = new JsonConfig();
                                    detailsCfg.setPropertySetStrategy(new PropertyStrategyWrapper(
                                            PropertySetStrategy.DEFAULT));
                                    detailsCfg.setRootClass(YouKuVideoDetailInfoJSON.class);
                                    YouKuVideoDetailInfoJSON infoDetailsArray = (YouKuVideoDetailInfoJSON) JSONObject
                                            .toBean(jsonDetails, detailsCfg);

                                    // Saves to DB
                                    infoManager.saveOrUpdate(convert(infoDetailsArray));

                                    // Saves all persons to DB
                                    List<com.bestv.search.spider.model.Person> list = getPersonList(infoDetailsArray);
                                    personManager.saveList(list);
                                } else {
                                    return false;
                                }
                            } else {
                                return false;
                            }
                        }
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }

                if (pageIndex >= pageSize) {
                    break;
                }
                pageIndex++;
            } while (true);
        }

        return true;
    }

    private List<VideoBaseInfo> convert(YouKuVideoDetailInfoJSON infoJSON) {
        List<VideoBaseInfo> baseInfos = new ArrayList<VideoBaseInfo>();
        for (YouKuVideoDetailInfo info : infoJSON.getShows()) {
            info.setHasvideoType(StringUtil.buildBuffer(info.getHasvideotype(), SpiderConst.COMMA).toString());
            info.setStreamTypes(StringUtil.buildBuffer(info.getStreamtypes(), SpiderConst.COMMA).toString());
            info.setSource(SpiderConst.YOUKU);
            info.setUpdateTime(new Date());

            VideoAttr attr = info.getAttr();
            if (attr != null) {
                info.setDirectors(convertToStr(attr.getDirector()));
                info.setProducers(convertToStr(attr.getProducer()));
                info.setScreenwriters(convertToStr(attr.getScreenwriter()));
                info.setStarrings(convertToStr(attr.getStarring()));
                info.setPerformers(convertToStr(attr.getPerformer()));
                info.setOriginals(convertToStr(attr.getOriginal()));
                info.setVoices(convertToStr(attr.getVoice()));
                info.setHotcommentsSyncTime(new Date());
            }
            baseInfos.add(info);
        }
        return baseInfos;
    }

    private List<com.bestv.search.spider.model.Person> getPersonList(YouKuVideoDetailInfoJSON infoJSON) {
        List<com.bestv.search.spider.model.Person> list = new ArrayList<com.bestv.search.spider.model.Person>();

        List<Person> personInJson = new ArrayList<Person>();
        for (YouKuVideoDetailInfo info : infoJSON.getShows()) {
            if (info.getAttr() != null) {
                // Gets directors
                if (info.getAttr().getDirector() != null && info.getAttr().getDirector().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getDirector()));
                }

                // Gets Producers
                if (info.getAttr().getProducer() != null && info.getAttr().getProducer().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getProducer()));
                }

                // Gets Screen writers
                if (info.getAttr().getScreenwriter() != null && info.getAttr().getScreenwriter().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getScreenwriter()));
                }

                // Gets starring
                if (info.getAttr().getStarring() != null && info.getAttr().getStarring().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getStarring()));
                }

                // Gets performer
                if (info.getAttr().getPerformer() != null && info.getAttr().getPerformer().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getPerformer()));
                }

                // Gets original
                if (info.getAttr().getOriginal() != null && info.getAttr().getOriginal().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getOriginal()));
                }

                // Gets voices
                if (info.getAttr().getVoice() != null && info.getAttr().getVoice().length > 0) {
                    personInJson.addAll(Arrays.asList(info.getAttr().getVoice()));
                }
            }
        }

        Collections.sort(personInJson, new Comparator<Person>() {
            @Override
            public int compare(Person p1, Person p2) {
                return p1.getId().compareTo(p2.getId());
            }
        });

        // Convert to com.bestv.search.spider.model.Person
        if (personInJson != null && personInJson.size() > 0) {
            Person lastPerson = null;
            for (Person person : personInJson) {
                if (lastPerson == null || !lastPerson.getId().equals(person.getId())) {
                    com.bestv.search.spider.model.Person p = new com.bestv.search.spider.model.Person();
                    p.setPersonId(person.getId());
                    p.setName(person.getName());
                    p.setSource(SpiderConst.YOUKU);
                    list.add(p);
                }
                lastPerson = person;
            }
        }

        return list;
    }

    private String convertToStr(Person[] persons) {
        StringBuilder sb = new StringBuilder();
        if (persons != null && persons.length > 0) {
            for (int i = 0; i < persons.length; i++) {
                sb.append(persons[i].getName());
                if (i < persons.length - 1) {
                    sb.append(SpiderConst.COMMA);
                }
            }
        }
        return sb.toString();
    }

    private String getFileFolderByDateTime(Date date) {
        String baseFolder = this.getInfoFolder() + File.separator + SpiderConst.BASE;
        File folder = new File(baseFolder);
        if (!folder.exists()) {
            folder.mkdir();
        }

        baseFolder = baseFolder + File.separator + SpiderConst.YOUKU;
        folder = new File(baseFolder);
        if (!folder.exists()) {
            folder.mkdir();
        }

        SimpleDateFormat format = new SimpleDateFormat(SpiderConst.DATETIME_FORMAT);
        String dateTimeFolder = baseFolder + File.separator + format.format(date);
        folder = new File(dateTimeFolder);
        if (!folder.exists()) {
            folder.mkdir();
        }
        return dateTimeFolder;
    }

    private String convertToJson(YouKuVideoDetailInfo detailInfo) {
        JSONObject json = new JSONObject();
        json.put(SpiderConst.ID, detailInfo.getId());
        json.put(SpiderConst.NAME, detailInfo.getName());
        json.put(SpiderConst.CATEGORY, detailInfo.getCategory());
        json.put(SpiderConst.GENRE, detailInfo.getGenre());
        json.put(SpiderConst.AREA, detailInfo.getArea());
        json.put(SpiderConst.RELEASED, detailInfo.getReleased());
        json.put(SpiderConst.DESCRIPTION, detailInfo.getDescription());
        json.put(SpiderConst.DIRECTORS, detailInfo.getDirectors());
        json.put(SpiderConst.SCREENWRITERS, detailInfo.getScreenwriters());
        json.put(SpiderConst.PRODUCERS, detailInfo.getProducers());
        json.put(SpiderConst.STARRINGS, detailInfo.getStarrings());
        json.put(SpiderConst.PERFORMERS, detailInfo.getPerformers());
        json.put(SpiderConst.ORIGINALS, detailInfo.getOriginals());
        json.put(SpiderConst.VOICES, detailInfo.getVoices());
        json.put(SpiderConst.COMPLETED, detailInfo.getCompleted());
        json.put(SpiderConst.EPISODE_COUNT, detailInfo.getEpisode_count());
        json.put(SpiderConst.EPISODE_UPDATED, detailInfo.getEpisode_updated());
        json.put(SpiderConst.VIEW_COUNT, detailInfo.getView_count());
        json.put(SpiderConst.FAVORITE_COUNT, detailInfo.getFavorite_count());
        json.put(SpiderConst.SOURCE, SpiderConst.YOUKU);
        json.put(SpiderConst.YOUKUSCORE, detailInfo.getScore());

        return json.toString();
    }

    public void setInfoManager(VideoBaseInfoManager infoManager) {
        this.infoManager = infoManager;
    }

    public String getIsfullSync() {
        return isfullSync;
    }

    public void setIsfullSync(String isfullSync) {
        this.isfullSync = isfullSync;
    }

    public YouKuVideoDetailInfoManager getYouKuVideoDetailInfoManager() {
        return youKuVideoDetailInfoManager;
    }

    public void setYouKuVideoDetailInfoManager(YouKuVideoDetailInfoManager youKuVideoDetailInfoManager) {
        this.youKuVideoDetailInfoManager = youKuVideoDetailInfoManager;
    }

    public String getInfoFolder() {
        return infoFolder;
    }

    public void setInfoFolder(String infoFolder) {
        this.infoFolder = infoFolder;
    }

    public PersonManager getPersonManager() {
        return personManager;
    }

    public void setPersonManager(PersonManager personManager) {
        this.personManager = personManager;
    }
}
